from core import *


class Cart(Seeker):
    color     =_ (Chocolate.with_saturation(0.8))
    roadbound =_ (True)
    speed     =_ (7)
    capacity  =_ (400)
    
    destination = Attribute()
    job         = Attribute()
    good        = Attribute()
    
    def birth(self):
        self.move_to(self.destination)
        self.job.add_incoming(self, self.capacity)
        self.on_leaving_home()
    
    def return_home(self):
        self.job.remove_incoming(self)
        self.move_home()
        
    def on_idle(self):
        self.return_home()
    
    def on_dead_end(self):
        self.return_home()
    
    def on_leaving_home(self):
        pass


class FetchCart(Cart):
    def on_arrival_away(self):
        self.take_from(self.destination, self.good(self.capacity))

    def on_arrival_home(self):
        self.unload_into(self.home)
        self.destroy()


class DeliveryCart(Cart):
    def on_leaving_home(self):
        self.take_from(self.home, self.good(self.capacity))
    
    def on_arrival_away(self):
        self.unload_into(self.destination)
    
    def on_arrival_home(self):
        self.unload_into(self.home)
        self.destroy()
